
(defun != (arg1 arg2) "Returns true if arg1 is not equal to arg2"
  (not (equal arg1 arg2))
)



(defun isIncluded (word list) "Checks to see if word is included in list"
  (if (equal word (car list))

    ;;then
    t

    ;;else
    (if (!= list nil) (isIncluded word (cdr list)))

  )
)



(defun writeToFile (name content) "Writes a string to a file, this is not mine. http://www.socher.org/index.php/Main/WriteToFileInLisp"
  (with-open-file (stream  name :external-format charset:iso-8859-1
                           :direction :output
                           :if-exists :overwrite
                           :if-does-not-exist :create )
  (format stream content))
name)


(defun item-from-listnest (x y list) "Returns from a list of lists, the xth item of the yth list"
  (nth (- x 1) (nth (- y 1) list))

) 


(defun flatten (lis)
"Removes parenthetical nestings from a list. Not mine. http://cogsci.uwaterloo.ca/CoherenceCode/COHERE/utilities.lisp.html"
(cond ((atom lis) lis)
((listp (car lis))
(append (flatten (car lis)) (flatten (cdr lis)))
)
(t (append (list (car lis)) (flatten (cdr lis))))
)
)

(defun wordindex (item list) "returns the index value of an item in a list"
  (let (
       (counter 0)
       (templist list)
       (blah nil)
       )
       (while templist do
	      (if (equal (nth counter list) item)
		  (setq blah counter)
	      )
	      (setq counter (1+ counter))
	      (setq templist (cdr templist))
       )
       blah
  )
)



(defun last-n-char (n string) "returns the last n characters in a string"

  (if (>= (length string) n) ;;make sure the start point is always valid

      ;;then
      (setq start (- (length string) n))
      
      ;;else
      (setq start 0)
  )

  (subseq string start (length string))
)


(defun symbols-to-list (list) "makes symbols to lists, '(a b c (a b)) --> '((a) (b) (c) (a b))"

  (let  (
	(templist list)
	(newlist list)
	)
  (while templist do
	 (if (equal (type-of (car templist)) 'symbol)
	     (setf (nth (position (car templist) newlist) newlist) (list (car templist)))
	 )
	 (setq templist (cdr templist))
  )
  newlist
  )
)


(defun group-items (list) "turns items in a list separated by lists into a single list, ex: (a b c d (e f) g h (i) j k l) --> ((a b c d) (e f) (g h) (i) (j k l)), this is used in tandem with the sentence parser to break the sentence into verbs and phrases between verbs"
  (let (
       (templist list)
       (addlist '())
       (outputlist '())
       )
    

  (while templist do
       (if (equal (type-of (car templist)) 'cons)
	   (progn
	   (setq outputlist (left-rotate (cons addlist outputlist)))
	   (setq outputlist (left-rotate (cons (car templist) outputlist)))
	   (setq addlist '())
	   )
       )
       
       (if (equal (type-of (car templist)) 'symbol)
	   (setq addlist (left-rotate (cons (car templist) addlist)))
       )

       (if (equal (length templist) 1)
	   (setq outputlist (left-rotate (cons addlist outputlist)))
       )

       (setq templist (cdr templist))
  )

  (remove nil outputlist)
  )
)

(defun find-item (word list) "takes a list of nested lists and returns all the list in which an item occurs, ex: (find-item 'a ((a b c) (d e f) (a b h))) --> ((a b c) (a b h)), input must be made solely of lists"

  (let (
       (templist list)
       (outputlist '())
       )
  
  (while templist do
       (if (isincluded word (car templist))
	   (setq outputlist (left-rotate (cons (car templist) outputlist)))
       )
       (setq templist (cdr templist))
  )
  outputlist
  )

)


(defun unique (list) "removes duplicates from a list"
  (let (
       (templist list)
       (outputlist '())
       )
  (while templist do
       (if (not (isincluded (flatten (car templist)) outputlist))
	   (setq outputlist (left-rotate (cons (flatten (car templist)) outputlist)))
       )
       (setq templist (cdr templist))
  )
  outputlist
  )
)